const ret = new Array(100)
  .fill(null)
  .map((_, i) => i + 1)
  .reduce((pre, cur) => pre + cur);

console.log(ret);

function factorial(num) {
  return new Array(num)
    .fill(null)
    .map((_, i) => i + 1)
    .reduce((pre, cur) => pre * cur, 1);
}

console.log(factorial(5));

function getArrOddCountAndSum(arr) {
  return arr.reduce(
    (pre, cur) => {
      /* if (cur % 2 === 1) {
        pre.count += 1;
        pre.sum += cur;
      } else {
        pre.count += 0;
        pre.sum += 0;
      }
      return pre; */

      cur % 2 === 1
        ? ((pre.count += 1), (pre.sum += cur))
        : ((pre.count += 0), (pre.sum += 0));

      return pre;
    },
    {
      count: 0,
      sum: 0,
    }
  );
}

console.log(getArrOddCountAndSum([1, 2, 3, 54, 231, 4]));
